<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/users.php';
require_once "../../includes/classes/paging_htacess.php";
require_once '../../redirect.php';
## creating objects of required models
$userObj 		= new Model_Users();


checkUserLogin();
if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}


$userId =$_SESSION['getbids_id'];
	
/*===========================================================================*/
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
	$smarty->assign("userDetArray", $userDetArray);	
	
/*===========================================================================*/	


## for pagination
	$page = $_GET['id1'];
	if(!isset($_GET['id1']))
	$page = 1;
	else
	$page = $page;
	
## limit per pag 
$tetsimonialPerPage =10;
$StartRow = $tetsimonialPerPage  * ($page-1);
## Getting all jobs from database according to user
if($_POST['search']!='' && $_POST['search']!='Homeowner Name')
{
	$search = addslashes($_POST['search']); 
} 
elseif($_GET['id2']!='')
{
	$search =addslashes($_GET['id2']); 
}
else {
	$search = '';
}
$smarty -> assign("search",stripslashes (stripslashes ($search)));

$reviewsArray  = $userObj->getReviewByUserId($userId,$search,$col1='','','',false);
$totalCount        = count($reviewsArray);
$smarty -> assign("recordsFound",$totalCount);

$result = $userObj->getReviewByUserId($userId,$search,$col1='',$tetsimonialPerPage,$StartRow,true);
$show = 1;
$total_pages = ceil($totalCount / $tetsimonialPerPage);
	if($total_pages > 1)
	$smarty -> assign("showpgnation","yes");
	$showing    = !isset($_GET["id1"]) ? 1 : $page;
	
	## it shoould be file name 
	if($search!='')
	{
		$firstlink  ="".$search."/rating/";
	}
	else
		$firstlink  ="rating/";		
		
	$baselink   = $firstlink;
	if($total_pages!=0)
		$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink, "", "rating");
	$smarty -> assign("pagenation", $pagenation);
	$smarty -> assign("page", $page);
//	echo"<pre>";print_R($userrating);die();
	for($k=0;$k<count($result);$k++)
	{		
		if($result[$k]['rating']!='0')
		{			
			$total_rating = $result[$k]['rating'];
			$result[$k]['total_rating'] =$total_rating;
			//$smarty->assign('total_rating', $total_rating);
			if($total_rating < 5){
				$remaining_rating = 5 - $total_rating;
				$result[$k]['remaining_rating'] =$remaining_rating;
				//$smarty->assign('remaining_rating', $remaining_rating);
			} 
		}
		else
		{
			$result[$k]['total_rating'] =0;	
			$result[$k]['remaining_rating'] =5;
		}
	}	
	
	$smarty->assign("reviewsArray", $result);



if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
}

$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="rating";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"6");

$smarty->display(TEMPLATEDIR.'/modules/rating/rating.tpl');
unset($smarty);
?>
